package com.mdd.product.controller.car;

import com.mdd.common.aop.CurrentUser;
import com.mdd.common.aop.Log;
import com.mdd.common.aop.NotPower;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validate.AddGroup;
import com.mdd.common.validate.EditGroup;
import com.mdd.common.validator.annotation.IDMust;
import com.mdd.product.service.IProductSpuService;
import com.mdd.product.validate.ProductSpuSearchValidate;
import com.mdd.product.validate.car.CarSpuValidate;
import com.mdd.product.vo.CarSpuDetailVo;
import com.mdd.product.vo.CarSpuListVo;
import com.mdd.system.vo.SystemAuthAdminInformVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * 运营车品管理接口
 * @Description
 * @Author 幻速
 * @Date 2024/3/7 14:16
 **/
@RestController
@RequestMapping("api/car/spu")
@Api(tags = "零售车品管理")
public class CarProductController {
    @Resource
    IProductSpuService iProductSpuService;
    //商品列表
    @NotPower
    @GetMapping("/page")
    @ApiOperation(value="商品分页列表")
    public AjaxResult<PageResult<CarSpuListVo>> cars(@Validated ProductSpuSearchValidate searchValidate, @CurrentUser SystemAuthAdminInformVo systemAuthAdmin) {
        if (Objects.isNull(searchValidate.getPType())){
            searchValidate.setPType(1);
        }
        return AjaxResult.success(iProductSpuService.cars(searchValidate,systemAuthAdmin));
    }
    //商品详情
    @NotPower
    @GetMapping("/detail")
    @ApiOperation(value="商品详情")
    public AjaxResult<CarSpuDetailVo> carSpuDetail(@Validated @IDMust() @RequestParam("id") Long id) {
        return AjaxResult.success(iProductSpuService.carSpuDetail(id));
    }
    //添加车品
    @NotPower
    @Log(title = "商品新增")
    @PostMapping("/add")
    @ApiOperation(value="商品新增")
    public AjaxResult<Object> addCarSpu(@Validated(AddGroup.class) @RequestBody CarSpuValidate createValidate, @CurrentUser SystemAuthAdminInformVo systemAuthAdmin) {
        iProductSpuService.addCarSpu(createValidate,systemAuthAdmin);
        return AjaxResult.success();
    }
    //编辑车品
    @NotPower
    @Log(title = "商品编辑")
    @PostMapping("/edit")
    @ApiOperation(value="商品编辑")
    public AjaxResult<Object> editCarSpu(@Validated(EditGroup.class) @RequestBody CarSpuValidate carSpuValidate) {
        iProductSpuService.editCarSpu(carSpuValidate);
        return AjaxResult.success();
    }
}
